# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 16:19:29 2020

@author: Administrator
"""

'''
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?


Example 2:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Down -> Down
2. Down -> Down -> Right
3. Down -> Right -> Down
Example 3:

Input: m = 7, n = 3
Output: 28
Example 4:

Input: m = 3, n = 3
Output: 6

'''

class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        '''
        20200919--李运辰
        算法易懂，多看几遍
        '''
        p = [[0]*n for _ in range(m)]
        for i in range(m):
            for j in range(n):
                if i==0 or j==0:
                    p[i][j] = 1
                else:
                    p[i][j] = p[i][j-1]+p[i-1][j]
        return p[m-1][n-1]